var app = getApp();

Page({
    data: {
        imgList:"",
        activeList:"",
        activeId:"",
        activeName:"",
        saleList:"",
        saleId:"",
        saleName:"",
        imgUrl:app.globalData.imgUrl,
    },
    onLoad: function () {
        var that = this;
        that.setData({
           navH: app.globalData.navHeight,
           marH: app.globalData.navHeight+20
        })
        that.getImg();
        that.getActiveCategory();
    },
    onShareAppMessage() {
        return {
          title: '在海花岛这样订房也不错，快看快约！',
          //path: '/pages/serve/serve-index'
          path: 'pages/index/index?url=/pages/serve/serve-index'
        }
    },
    getImg:function(){
        var that = this;
        wx.request({
            url: app.globalData.apiHost + "/api/index/bannerList",
            data: {
                position: "activicy"
            },
            header: {  
                'content-type': 'application/json' 
            },
            method: "GET",
            dataType: "json",
            success: function (res) {
                if (res.statusCode === 200) {
                    var imgData = res.data.data;
                    that.setData({
                        imgList: imgData
                    })
                }
            },
            
        });
    },
    getActiveCategory: function () {
        var that=this;
        wx.request({
            url: app.globalData.apiHost + "/api/index/serviceCategoryList",
            data: {
                type: 1
            },
            header: {
                'content-type': 'application/json'
            },
            method: "GET",
            dataType: "json",
            success: function (res) {
                if (res.statusCode === 200) {
                    //获取"活动"和"特价"相关信息
                    var activeIdData=res.data.data[0].childlist[1].id;
                    var activeNameData=res.data.data[0].childlist[1].name;
                    var saleIdData=res.data.data[0].childlist[2].id;
                    var saleNameData=res.data.data[0].childlist[2].name;
                    that.setData({
                        activeId: activeIdData,
                        activeName: activeNameData,
                        saleId: saleIdData,
                        saleName: saleNameData
                    });
                    that.getActive();
                    that.getSale();
                }
            },
            
        })
    },
    getActive:function(){
        var that = this;
        wx.request({
            url: app.globalData.apiHost + "/api/index/goodsList",
            data: {
                page:1,
                pagesize:2,
                category_id:that.data.activeId
            },
            header: {  
                'content-type': 'application/json' 
            },
            method: "GET",
            dataType: "json",
            success: function (res) {
                if (res.statusCode === 200) {     
                    var activeData = res.data.data.data;
                    that.setData({
                        activeList: activeData
                    })
                }
            },
            
        });
    },
    getSale:function(){
        var that = this;
        wx.request({
            url: app.globalData.apiHost + "/api/index/goodsList",
            data: {
                page:1,
                pagesize:4,
                category_id:that.data.saleId
            },
            header: {  
                'content-type': 'application/json' 
            },
            method: "GET",
            dataType: "json",
            success: function (res) {
                if (res.statusCode === 200) {
                    var saleData = res.data.data.data;
                    console.log(saleData);
                    that.setData({
                        saleList: saleData
                    })
                }
            },
            
        });
    },
  })
  